package com.ssit.answer.controller.${packageDir};

import java.util.List;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssit.answer.conts.ErrorCode;
import com.ssit.answer.dto.ResultDto;
import com.ssit.answer.exception.BaseException;
import com.ssit.answer.exception.ExceptionUtil;
import com.ssit.answer.service.api.${packageDir}.I${className}Service;
import com.ssit.answer.domain.${packageDir}.${className};

/**
* 描述:<br/>
* ${comment!""} - 接口控制层
*
* @author ${author} ${.now?string("yyyy年MM月dd日")}
*/
@Controller
@RequestMapping(value = "/${className?uncap_first}")
public class ${className}Controller {

	Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	I${className}Service ${className?uncap_first}Service;
	
	/**
	 * 新增信息
	 * 
	 * @param ${className?uncap_first} 对象信息
	 */
	@ResponseBody
	@RequestMapping(value="/add${className}")
	public ResultDto add${className}(@RequestBody ${className} ${className?uncap_first}) {
		try {
			${className?uncap_first}Service.add${className}(${className?uncap_first});
			return ResultDto.success("新增成功");
		} catch (Exception e) {
			if(e instanceof BaseException) {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.add${className}(${className?uncap_first})发生业务异常",e);
				return ResultDto.failed(e.getMessage());
			}else {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.add${className}(${className?uncap_first})发生系统异常",e);
				return ResultDto.failed(ExceptionUtil.getErrorMessage(ErrorCode.BASE_SERVER_ERROR));
			}
		}		
	}


	/**
	 * 修改信息
	 * 
	 * @param ${className?uncap_first} 对象信息
	 */
	@ResponseBody
	@RequestMapping(value="/update${className}")
	public ResultDto update${className}(@RequestBody ${className} ${className?uncap_first}) {
		try {
			${className?uncap_first}Service.update${className}(${className?uncap_first});
			return ResultDto.success("修改成功");
		} catch (Exception e) {
			if(e instanceof BaseException) {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.update${className}(${className?uncap_first})发生业务异常",e);
				return ResultDto.failed(e.getMessage());
			}else {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.update${className}(${className?uncap_first})发生系统异常",e);
				return ResultDto.failed(ExceptionUtil.getErrorMessage(ErrorCode.BASE_SERVER_ERROR));
			}
		}		
	}
	
	/**
	 * 删除信息
	 * 
	 * @param ${className?uncap_first} 对象信息
	 */
	@ResponseBody
	@RequestMapping(value="/delete${className}")
	public ResultDto delete${className}(@RequestBody ${className} ${className?uncap_first}) {
		try {
			${className?uncap_first}Service.delete${className}(${className?uncap_first});
			return ResultDto.success("删除成功");
		} catch (Exception e) {
			if(e instanceof BaseException) {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.delete${className}(${className?uncap_first})发生业务异常",e);
				return ResultDto.failed(e.getMessage());
			}else {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.delete${className}(${className?uncap_first})发生系统异常",e);
				return ResultDto.failed(ExceptionUtil.getErrorMessage(ErrorCode.BASE_SERVER_ERROR));
			}
		}		
	}
	
	/**
	 * 查找信息
	 * 
	 * @param ${className?uncap_first} 对象信息
	 */
	@ResponseBody
	@RequestMapping(value="/find${className}")
	public ResultDto find${className}(@RequestBody ${className} ${className?uncap_first}) {
		try {
			return ResultDto.success(${className?uncap_first}Service.find${className}(${className?uncap_first}));
		} catch (Exception e) {
			if(e instanceof BaseException) {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.find${className}(${className?uncap_first})发生业务异常",e);
				return ResultDto.failed(e.getMessage());
			}else {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.find${className}(${className?uncap_first})发生系统异常",e);
				return ResultDto.failed(ExceptionUtil.getErrorMessage(ErrorCode.BASE_SERVER_ERROR));
			}
		}		
	}
	
	/**
	 * 查询信息列表
	 * 
	 * @param ${className?uncap_first} 对象信息
	 */
	@ResponseBody
	@RequestMapping(value="/list${className}")
	public ResultDto list${className}(@RequestBody ${className} ${className?uncap_first}) {
		try {
			return ResultDto.success(${className?uncap_first}Service.list${className}(${className?uncap_first}));
		} catch (Exception e) {
			if(e instanceof BaseException) {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.list${className}(${className?uncap_first})发生业务异常",e);
				return ResultDto.failed(e.getMessage());
			}else {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.list${className}(${className?uncap_first})发生系统异常",e);
				return ResultDto.failed(ExceptionUtil.getErrorMessage(ErrorCode.BASE_SERVER_ERROR));
			}
		}		
	}
	
	/**
	 * 查询分信息列表
	 * 
	 * @param ${className?uncap_first} 对象信息
	 */
	@ResponseBody
	@RequestMapping(value="/page${className}")
	public ResultDto page${className}(@RequestBody ${className} ${className?uncap_first}) {
		try {
			return ResultDto.success(${className?uncap_first}Service.page${className}(${className?uncap_first}));
		} catch (Exception e) {
			if(e instanceof BaseException) {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.page${className}(${className?uncap_first})发生业务异常",e);
				return ResultDto.failed(e.getMessage());
			}else {
				logger.error("调用com.ssit.answer.controller.${packageDir}.${className}Controller.page${className}(${className?uncap_first})发生系统异常",e);
				return ResultDto.failed(ExceptionUtil.getErrorMessage(ErrorCode.BASE_SERVER_ERROR));
			}
		}		
	}

}